<?php
	session_start();
	
	include('dbPostgres.php');
	
	if(IsSet($_POST['action'])) {
		$action = $_POST['action'];
	} else {
		$action = '';
	}
	
	if(IsSet($_POST['password'])) {
		$formPass = $_POST['password'];
	} else {
		$formPass = '';
	}
	
	if($action == 'login') {
		//pobranie hasla z bazy danych
		$db	= new dbPostgres();
		if(!$db->connect()) {
			die('Nie można połączyć się z bazą danych');
		} else {
			$db->query("SELECT value FROM \"" . $configDbPrefix . "config\" WHERE name='CONFIG_PANEL_PASSWORD' LIMIT 1;");
			$rows	= $db->fetchArray();
			foreach($rows as $row) {
				$dbPass = $row['value'];
			}
		}
	
		if($dbPass == md5($formPass)) {
			$_SESSION['login'] = true;
		} else {
			$loginFailed = true;
		}
	} else if($action == 'logout') {
		$_SESSION['login'] = false;
		session_destroy();
	}
?>
<html>
<head>
	<meta name="author" content="Krzysztof Ulman" />
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta http-equiv="Content-Language" content="pl" />
	<link rel="stylesheet" href="style.css" type="text/css" media="screen">
	<script src="scripts/jquery-tooltip/lib/jquery.js" type="text/javascript"></script>
	<script src="scripts/jquery-tooltip/lib/jquery.bgiframe.js" type="text/javascript"></script>
	<script src="scripts/jquery-tooltip/lib/jquery.dimensions.js" type="text/javascript"></script>
	<script src="scripts/jquery-tooltip/jquery.tooltip.js" type="text/javascript"></script>
	<title>OmnibusProxy - panel administracyjny</title>
</head>
<body>
<?php include('developmentInfo.php'); ?>
<div style="width: 100%; height: 100%; text-align: center; vertical-align: middle">
	<br>
	<h2>OmnibusProxy - panel administracyjny</h2>
	<br>
	<center>
		<div style="width: 440px; border: 1px solid black; padding: 20 px; overflow:visible;" align="center" valign="middle">
		<?php
		if($_SESSION['login'] == true) {
			?>
			<br>
			<form method="GET" action="./Configuration/indexConfiguration.php">
			<input type="hidden" name="configType" value="manageProxies">
				<button type="submit" class="submit">&nbsp;<img src="images/monitoring.png">&nbsp;&nbsp;&nbsp;Zarządzanie serwerami proxy</button>
			</form>
			<br>
			<form method="GET" action="./Configuration/indexConfiguration.php">
				<input type="hidden" name="configType" value="manageSearchers">
				<button type="submit" class="submit">&nbsp;<img src="images/checker.gif">&nbsp;&nbsp;&nbsp;Zarządzanie wyszukiwarkami</button>
			</form>
			<br>
			<!--<form method="GET" action="./CrawlerChecker/indexCrawler.php" target="_blank">
				<button type="submit" class="submit">&nbsp;<img src="images/eye.png">&nbsp;&nbsp;&nbsp;CrawlerChecker - poprawność rozpoznawania treści</button>
			</form>
			<br>-->
			<form method="GET" action="./Configuration/indexConfiguration.php">
				<input type="hidden" name="configType" value="showResults">
				<button type="submit" class="submit">&nbsp;<img src="images/eye.png">&nbsp;&nbsp;&nbsp;Zarządzanie hasłami i przeglądanie wyników</button>
			</form>
			<br>
			<form method="GET" action="./Configuration/indexConfiguration.php">
				<input type="hidden" name="configType" value="advancedConfig">
				<button type="submit" class="submit">&nbsp;<img src="images/config.png">&nbsp;&nbsp;&nbsp;OmnibusProxy - konfiguracja zaawansowana</button>
			</form>
			<br>
			<!--<form method="GET" action="./OmnibusProxyHomePage" target="_blank" style="display: inline;">
				<button type="submit" class="submitSmall">&nbsp;<img src="images/www.png">&nbsp;&nbsp;&nbsp;Strona robota</button>
			</form>-->
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<form method="POST" action="<?php echo $PHP_SELF ?>" style="display: inline;">
				<input type="hidden" name="action" value="logout">
				<button type="submit" style="text-align: right;" class="submitSmall">Wyloguj&nbsp;&nbsp;&nbsp;<img src="images/logout.png">&nbsp;</button>
			</form>
			<?php
		} else {
			?>
			<br><br>
			<?php
				if($loginFailed) {
					?>
					<div style="color: red; display: inline;">Logowanie nieudane.</div>
					<?php
				}
			?>
			<br><br>
			<form method="POST" action="<? echo $PHPSELF ?>">
				Twoje hasło:&nbsp;
				<input type="password" name="password" width="20">
				&nbsp;
				<input type="hidden" name="action" value="login">
				<button type="submit">&nbsp;<img src="images/logout.png">&nbsp;&nbsp;&nbsp;Zaloguj</button>
			</form>
			<br><br>
			<?php
		}
		?>
		<br>
		<br>
		</div>
		<br>
		<div style="font-size: 13px;">
			Copyright &copy; 2012 Krzysztof Ulman<br>
			<br>
			Praca dyplomowa magisterska.<br>
			Instytut Teleinformatyki, Politechnika Krakowska.
		</div>
		</center>
</div>
<script>
	$("#helpAdvancedConfig").tooltip({ 
    delay: 0, 
    showURL: false, 
    bodyHandler: function() { 
        return $("<img/>").attr("src", "images/help.gif"); 
    } 
});
</script>
</body>